from pyrogram import filters, Client
from pyrogram.types.messages_and_media import Message
from pyrogram.enums import ParseMode

from app import app, logger
from app.libs.user import AsyncUser
from app.models import Session


@app.on_message(filters.me & filters.command("message") & filters.reply)
async def getmessage(client: Client, message: Message):
    await message.delete()
    logger.info(str(message.reply_to_message))
    await app.send_message("me", f"```\n{str(message.reply_to_message)}```")


@app.on_message(filters.me & filters.command("test"))
async def test_my_bot(client: Client, message: Message):
    logger.info("脚本运行中")
    await message.delete()


@app.on_message(filters.me & filters.command("add"))
async def test_my_bot(client: Client, message: Message):
    async with Session() as session:
        async with session.begin():
            async with AsyncUser(message, session) as user:
                print(user.tgbot.name)
                print(user.tgbot.user)

                user.tgbot.user.add(1)
                await message.reply(user.tgbot.user.amount)


@app.on_message(filters.me & filters.regex("/mdtest (.*)"))
async def test_my_bot(client: Client, message: Message):
    match = message.matches[0]
    string = match.group(1)
    await client.send_message(message.chat.id, string, ParseMode.DISABLED)
